/*
	Copyright (C) 2008 by Jean-FranÁois Geyelin
	jfgeyelin@gmail.com

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the
	Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

/**
to do:

-faire que le serveur n'accepte pas 2 replays avec le meme ID
-faire que le son pour le saut ne chie pas trop
-faire que le joueur gicle correctement quand il saute sur mario
-faire qu'il y ai une histoire
-rajouter du random dans tous les niveaux
-ajouter des boites de shield un peu partout
-tÈlÈchargement d'une image/message


-mettre du son pour les bouttons du menu o˘ on regle le son

-verif que le seed influence les parties
-seed alÈatoire en solo


-drapeaux sur le site

-FAIRE QUE LES RESULTATS DES REPLAYS NE SOIENT PAS SEPARES PAR DES ":"!!!

*/



/**



*/


/**
trucs qui seraient bien:
-faire un niveau o˘ on se dÈplace super vite
-faire que le wiseguy donne le shield
-finish water slime
-collisions with snifit
*/

/**
trucs que je ne ferais pas:
-faire que certain niveaux n'apparaissent que en compÈtition
-faire qu'on puisse mourrir dans la map Simon (du premier coup)
*/




#include "compilationModifiers.h"
#include "globals.h"
#include "DisplayString.h"
#include "mtrand.h"
#include "joystick.h"
#include "handleArguments.h"
#include "mainMenu.h"
#include "settings.h"
#include "findPath.h"
#include "submitMenu.h"
#include "splashScreen.h"
#include "Audio.h"



#ifndef NO_LIBCURL
#ifndef __APPLE__
    #include <curl/curl.h>
    #include <curl/types.h>
    #include <curl/easy.h>
#endif
#endif



void cleanMainForExit(void) {

    MusicThread::deleteInstance();
    AllSounds::deleteInstance();
    DisplayString::free();
    AllTheImages::deleteInstance();
    ScreenClass::deleteInstance();


#ifndef NO_LIBCURL
#ifndef __APPLE__
    if (curlIsInitialized) {
        TEST_EXECUTION()
        curl_global_cleanup();
        curlIsInitialized = false;
    }
#endif
#endif
    PRINTF("KM successfully terminated.");
}




int main( int argc, char *args[]) {



    atexit(cleanMainForExit);
    curlIsInitialized = false;
    allSounds = NULL;

    musicThread = NULL;
    MTRand_int32 mtrand;
    myRandomMaker = &mtrand;


#ifndef NO_LIBCURL
#ifndef __APPLE__
    if (curl_global_init(CURL_GLOBAL_ALL)) {
        LOG_ERROR("failed to initialize curl.\n")
    }
    else {
        curlIsInitialized = true;
    }
#endif
#endif

    findPath();
   	quit = false;
   	ScreenClass::getInstance();
    AllTheImages::getInstance();
    DisplayString::init();
    Audio::init();
    AllSounds::getInstance();
    MusicThread::getInstance();

    if (!handleArguments(argc,args)) {
        return 0;
    }


    MusicThread::getInstance()->smoothlyStartPlayingMusic(MENU_MUSIC);
    initializeJoystick();
    splashScreen();
    mainMenu();
    return 0;
}

